package net.xdclass.service.controller;

import net.xdclass.service.domain.Product;
import net.xdclass.service.service.ProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: 何建文
 * create: 2020-07-18 15:44
 * description:
 **/
@RestController
@RequestMapping("/api/v1/product")
public class PaoductController {

    @Value("${server.port}")
    private int port;

    @Autowired
    private ProductService productService;

    @GetMapping("/list")
    public Object list() {
        return productService.listProduct();
    }

    @GetMapping("/findById")
    public Object findById(int id) {
        Product product = productService.findById(id);
        Product result = new Product();
        BeanUtils.copyProperties(product, result);
        result.setName(product.getName() + ": data is from " + port);
        return result;
    }
}
